package com.hamster.crm.web;

import com.hamster.crm.pojo.Scheme;
import com.hamster.crm.pojo.SchemeConfig;
import com.hamster.crm.pojo.SchemeEmployee;
import com.hamster.crm.pojo.SchemeResult;
import com.hamster.crm.service.SchemeService;
import com.hamster.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 后台方案执行管理【执行比例设置，添加方案，方案执行结果列表 】
 * @author Tarry
 * @create 2019/12/20 15:06
 */
@RestController
@RequestMapping("scheme")
public class SchemeController {
    @Autowired
    private SchemeService schemeService;

    /**
     * 执行比例设置
     * 新增一条方案执行情况的比例
     * @param schemeConfig
     * @return 状态码 200
     */
    @PostMapping("insertConfig")
    public ResponseEntity<Void> insertSchemeConfig(@RequestBody SchemeConfig schemeConfig){
        schemeService.insertSchemeConfig(schemeConfig);
        return ResponseEntity.ok().build();
    }

    /**
     * 执行比例设置
     * 获取方案执行比例参数列表
     * @return List<SchemeConfig> 状态码200
     */
    @GetMapping("listConfig")
    public ResponseEntity<List<SchemeConfig>> listSchemeConfig(){
        List<SchemeConfig> configList = schemeService.listSchemeConfig();
        return ResponseEntity.ok(configList);
    }

    /**
     * 执行比例设置
     * 根据id，删除方案执行比例参数配置
     * @param ids
     * @return
     */
    @PostMapping("deleteConfig")
    public ResponseEntity<Void> deleteSchemeConfig(@RequestBody List<String> ids){
        schemeService.deleteSchemeConfig(ids);
        return ResponseEntity.ok().build();
    }

    /**
     * 添加方案分栏
     * 添加一条方案
     * @param scheme
     * @return 状态码 200
     */
    @PostMapping("insert")
    public ResponseEntity<Void> insertScheme(@RequestBody Scheme scheme){
        schemeService.insertScheme(scheme);
        return ResponseEntity.ok().build();
    }

    /**
     * 添加方案分栏
     * 根据id删除指定方案
     * @param ids
     * @return 状态码200
     */
    @PostMapping("delete")
    public ResponseEntity<Void> deleteScheme(@RequestBody List<String> ids){
        schemeService.deleteScheme(ids);
        return ResponseEntity.ok().build();
    }

    /**
     * 添加方案分栏
     * 根据id下发方案
     * @param ids
     * @return 状态码200
     */
    @PostMapping("send")
    public ResponseEntity<Void> sendScheme(@RequestBody List<String> ids){
        schemeService.sendScheme(ids);
        return ResponseEntity.ok().build();
    }

    /**
     * 添加方案分栏
     * 获取当前所有方案列表
     * @return  List<Scheme>
     */
    @GetMapping("list")
    public ResponseEntity<List<Scheme>> listSchemes(){
        List<Scheme> schemeList = schemeService.listSchemes();
        return ResponseEntity.ok(schemeList);
    }

    /**
     * 方案执行结果列表
     * 根据条件分页查询，
     * @param pageSize     每页条数
     * @param currentPage  当前页号
     * @param title        标题
     * @param participant  参与人员
     * @return
     */
    @GetMapping("listResult")
    public ResponseEntity<PageResult<SchemeEmployee>> listSchemeResults(
            @RequestParam(required=false) Integer pageSize,
            @RequestParam(required=false) Integer currentPage,
            @RequestParam(required = false)String title,
            @RequestParam(required = false)String participant
    ){
        PageResult<SchemeEmployee> resultList = schemeService.listSchemeResults(title,participant,currentPage,pageSize);
        return ResponseEntity.ok(resultList);
    }

    /**
     * 根据 SchemeEmployee表的id，查询客户执行率详情
     * @param id
     * @return 详情 list 集合
     */
    @GetMapping("getSchemeDetails")
    public ResponseEntity<List<SchemeResult>> getSchemeDetails(String id){
        List<SchemeResult> list = schemeService.getSchemeDetails(id);

        return ResponseEntity.ok(list);
    }

}
